package com.itheima.controller.oms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.core.PageInfo;
import com.itheima.core.R;
import com.itheima.pojo.oms.*;
import com.itheima.pojo.oms.vo.OrderVo;
import com.itheima.pojo.oms.vo.receiverInfoParam;
import com.itheima.service.oms.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OmsOrderController {

    @DubboReference
    private OmsOrderService orderService;
    @DubboReference
    private OrderVoService orderVoService;

    @DubboReference
    private OmsOrderItemService omsOrderItemService;
    @DubboReference
    private OmsOrderOperateHistoryService omsOrderOperateHistoryService;
    @DubboReference
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    //批量删除订单
    @PostMapping("delete")
    public R delete(@RequestParam List<Integer> ids) {
        orderService.deleteIds(ids);
        return R.success("", "");
    }

    /*分页查询订单*/
    @GetMapping("list")
    public R list(@RequestParam int pageNum, @RequestParam int pageSize, String createTime, String orderSn,
                  Integer orderType, Integer sourceType, String receiverKeyword, Integer status) {

        PageInfo info = orderService.listAll(pageNum, pageSize, createTime, orderSn, orderType, sourceType, receiverKeyword, status);

        return R.success("", info);
    }

    /*批量关闭订单*/
    @PostMapping("/update/close")
    public R close(@RequestParam List<Integer> ids, @RequestParam String note) {
        orderService.colse(ids, note);
        return R.success("", "");
    }

    /*批量发货*/
    @PostMapping("/update/delivery")
    public R delivery(@RequestBody List<deliveryParamList> deliveryParamList) {
        orderService.delivery(deliveryParamList);
        return R.success();
    }

    /*修改订单费用信息*/
    @PostMapping("/update/moneyInfo")
    public R moneyInfo(@RequestBody moneyInfoParam moneyInfoParam) {
        orderService.moneyInfo(moneyInfoParam);
        return R.success();
    }

    /*备注订单*/
    @PostMapping("/update/note")
    public R note(@RequestParam Integer id, String note, Integer status) {
        orderService.note(id, note, status);
        return R.success();
    }

    /*修改收货人信息*/
    @PostMapping("/update/receiverInfo")
    public R receiverInfo(@RequestBody receiverInfoParam receiverInfoParam) {
        orderService.receiverInfo(receiverInfoParam);
        return R.success();
    }

    /*获取订单详情：订单信息、商品信息、操作记录*/
    @GetMapping("/{id}")
    public R GeiByID(@PathVariable int id) {

        OmsOrder orders = orderService.GeiByid(id);
        List<OmsOrderItem> orderItems = omsOrderItemService.GeiByID(id);
        List<OmsOrderOperateHistory> omsOrderOperateHistories = omsOrderOperateHistoryService.GeiByID(id);
        OrderVo orderVo = orderVoService.listall(orders, orderItems, omsOrderOperateHistories);

        return R.success("", orderVo);
    }
}
